//一些公用的请求事件
import {swiperActiveListUrl,swiperListUrl,uploadVoiceUrl,setForbinnenUrl,setUnForbinnenUrl } from '../../config';
import {showToast,get,post} from './index';


//请求轮播图
function getSwiperList(type){
	return new Promise((resolve,reject)=>{
		get(swiperListUrl, {
			type: type
		})
		.then((res)=>{
			if(res.code==200){
				resolve(res.data);
			}else{
				showToast(res.msg);
				reject();
			};
		});
	});
};

//请求活动轮播图
function getSwiperActiveList(type){
	return new Promise((resolve,reject)=>{
		get(swiperActiveListUrl, {
			type: type
		})
		.then((res)=>{
			if(res.code==200){
				resolve(res.data);
			}else{
				showToast(res.msg);
				reject();
			};
		});
	});
};



//聊天室上传语音
function uploadMusic(obj={}){
	return new Promise((resolve, reject)=>{
		post(uploadVoiceUrl, {
			mediaId: obj.mediaId,
			second: obj.second
		}, false)
		.then((res)=>{
			if(res.code==200){
				resolve(res.data.src);  //返回实际音频地址
			}else{
				showToast(res.msg);
				reject();
			};
		});
	});
};


//设置禁言
function setForbin(uid=''){
	return new Promise((resolve,reject)=>{
		post(setForbinnenUrl, {
			uid: uid,
		})
		.then((res)=>{
			if(res.code==200){
				resolve();
			}else{
				showToast(res.msg);
				reject();
			};
		});
	});
};

//解除禁言
function setUnForbin(uid=''){
	return new Promise((resolve,reject)=>{
		post(setUnForbinnenUrl, {
			uid: uid,
		})
		.then((res)=>{
			if(res.code==200){
				resolve();
			}else{
				showToast(res.msg);
				reject();
			};
		});
	});
};


module.exports = {
	getSwiperList,
	getSwiperActiveList,
	uploadMusic,
	setForbin,
	setUnForbin
};
